package org.jeecg.modules.merchant.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.merchant.controller.MerchantQuery;
import org.jeecg.modules.merchant.entity.Merchant;
import org.jeecg.modules.merchant.mapper.MerchantMapper;
import org.jeecg.modules.merchant.service.IMerchantService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 商户
 * @Author: jeecg-boot
 * @Date:   2019-10-03
 * @Version: V1.0
 */
@Service
public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> implements IMerchantService {

    @Override
    public IPage<Merchant> page(IPage<Merchant> page, MerchantQuery merchantQuery) {
        QueryWrapper<Merchant> queryWrapper =  new QueryWrapper<>();
        if(StringUtils.isNotBlank(merchantQuery.getName())){
            queryWrapper.like("name",merchantQuery.getName());
        }
        if(StringUtils.isNotBlank(merchantQuery.getAddress())){
            queryWrapper.like("address",merchantQuery.getAddress());
        }
        if(StringUtils.isNotBlank(merchantQuery.getAuditStatus())){
            queryWrapper.eq("audit_status",merchantQuery.getAuditStatus());
        }
        if(StringUtils.isNotBlank(merchantQuery.getType())){
            queryWrapper.eq("type",merchantQuery.getType());
        }
        if(StringUtils.isNotBlank(merchantQuery.getStartTime())){
            queryWrapper.ge("create_time",merchantQuery.getStartTime());
        }
        if(StringUtils.isNotBlank(merchantQuery.getEndTime())){
            queryWrapper.le("create_time",merchantQuery.getEndTime());
        }

        return this.page(page,queryWrapper);
    }

}
